﻿using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Instrument.Ports
{
#pragma warning disable CA1416
#pragma warning disable CA1416
#pragma warning disable CS8601 // Possible null reference assignment.
#pragma warning disable CS8600 // Converting null literal or possible null value to non-nullable type.

    public partial class WindowsApiSerialPort : IDisposable
    {
        public static string[] GetPortNames()
        {
            using (RegistryKey serialKey = Registry.LocalMachine.OpenSubKey(@"HARDWARE\DEVICEMAP\SERIALCOMM"))
            {
                if (serialKey != null)
                {
                    string[] result = serialKey.GetValueNames();
                    for (int i = 0; i < result.Length; i++)
                    {
                        // Replace the name in the array with its value.

                        result[i] = (string)serialKey.GetValue(result[i]);
                    }
                    return result;
                }
            }

#pragma warning disable IDE0301
            return [];
#pragma warning restore IDE0301
        }
    }

#pragma warning restore CS8600 // Converting null literal or possible null value to non-nullable type.
#pragma warning restore CS8601 // Possible null reference assignment.
#pragma warning restore CA1416
#pragma warning restore CA1416
}